package com.example.threaddemo;

import java.util.concurrent.TimeUnit;

/**
 * 可见性测试
 */
public class Demo1 {

    public static void main(String[] args) {
        MyData myData = new MyData();
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "     come in");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            myData.add60();
            System.out.println(Thread.currentThread().getName() + "     update ; value:" + myData.number);
        },"coco").start();

        while (myData.number == 0){
            
        }

        System.out.println(Thread.currentThread().getName() + "     over");
    }
}
